package com.wuhainan.beelzebub.service.system;

import com.wuhainan.beelzebub.common.BaseService;
import com.wuhainan.beelzebub.entity.system.ChargeItemType;
import com.wuhainan.beelzebub.repository.system.ChargeItemTypeRepository;
import com.wuhainan.beelzebub.utils.PageInfo;
import com.wuhainan.beelzebub.utils.TableData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <br>Created by 吴海南 on 2017-12-18.
 * <br>星期一 at 下午 3:05.
 */
@Service
public class ChargeItemTypeService extends BaseService<ChargeItemType>{
    @Resource
    private ChargeItemTypeRepository repository;

    public List<ChargeItemType> findByType(Integer type) {
        Sort sort=new Sort(Sort.Direction.ASC,"sort");
        return repository.findByType(type,sort);
    }

    public TableData findChargeItemTypePage(PageInfo pageInfo, ChargeItemType chargeItemType) {
        Page<ChargeItemType> page=repository.findAll((root, cq, cb) -> {
            search(chargeItemType, cq, cb, root);//模糊查询
            return cq.getRestriction();
        },pageable(pageInfo,sort(pageInfo, Sort.Direction.ASC,"sort")));
        return tableData(page);
    }
    public ChargeItemType findChargeItemTypeById(String id) {
        return repository.findOne(id);
    }

    /**
     * 保存费用项目类型
     *
     * @param chargeItemType 费用项目类型
     */
    public void saveChargeItemType(ChargeItemType chargeItemType) {
        repository.save(chargeItemType);
    }

    /**
     * 删除费用项目类型
     *
     * @param chargeItemType 费用项目类型
     */
    public void deleteChargeItemType(ChargeItemType chargeItemType) {
        repository.delete(chargeItemType);
    }

    public ChargeItemType findByTypeName(String typeName) {
        return repository.findByTypeName(typeName);
    }
}
